package top.tangyh.lamp.care.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Param;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BIoRecord;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.care.vo.query.SelectStatisticParam;
import top.tangyh.lamp.care.vo.result.*;
import top.tangyh.lamp.common.constant.CommonConstant;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 出入量记录表
 * </p>
 *
 * @author zqb
 * @date 2024-07-23 10:12:06
 * @create [2024-07-23 10:12:06] [zqb] [代码生成器生成]
 */
@Repository
public interface BIoRecordMapper extends SuperMapper<BIoRecord> {

    List<IoRecordVO> selectListOfRecordIo(SelectStatisticParam statisticParam);

    default List<BIoRecord> selectIoRecordByGroupId(String hospitalNumber, String patientIdent, String groupId, LocalDateTime planTime) {
        LambdaQueryWrapper<BIoRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BIoRecord::getHospitalNumber, hospitalNumber);
        wrapper.eq(BIoRecord::getPatientIdent, patientIdent);
        wrapper.eq(BIoRecord::getGroupId, groupId);
        wrapper.eq(BIoRecord::getPlanTime, planTime);
        wrapper.eq(BIoRecord::getIsMaster, CommonConstant.NO_NUMBER);
        List<BIoRecord> listIoRecord = this.selectList(wrapper);
        return listIoRecord;
    }

    List<BIoRecord> selectIoRecordOfList(@Param("hospitalNumber") String hospitalNumber, @Param("modelCode") String modelCode, @Param("startTime") String startTime, @Param("endTime") String endTime );


    /**
     * 统计某个选项的 早上7点到第二天7点的 总和 尿量
     */
    List<TemperateIODataVO> selectSumOfNlList(String hospitalNumber, String itemCode, String startTime, String endTime);


    List<TemperateIODataVO> selectSumOfLiuLiangList(String hospitalNumber, String startTime, String endTime);


    List<TemperateIODataVO> selectSumOfOutInList(String hospitalNumber, String startTime, String endTime);


    List<IoCodeDetailVO> selectIOOfDetail(String modelCode, String hospitalNumber, String startTime, String endTime);


    /**
     * 出入量 总模块统计
     *
     * @param hospitalNumber
     * @param startTimeA
     * @param endTimeA
     * @param startTimeP
     * @param endTimeP
     * @param startTimeN
     * @param endTimeN
     * @return
     */
    List<IoModelVO> selectSumOfModelAll(String hospitalNumber, String startTimeA, String endTimeA, String startTimeP, String endTimeP, String startTimeN, String endTimeN, Integer isShowCare);


    /**
     * 出入量 明细统计
     *
     * @param hospitalNumber
     * @param startTimeA
     * @param endTimeA
     * @param startTimeP
     * @param endTimeP
     * @param startTimeN
     * @param endTimeN
     * @return
     */
    List<IoDetailVO> selectSumOfDetailAll(String hospitalNumber, String startTimeA, String endTimeA, String startTimeP, String endTimeP, String startTimeN, String endTimeN, Integer isShowCare);


    default void deleteInOld(Long time, String operator, String account, String patientIdent, String hospitalNumber) {
        LambdaQueryWrapper<BIoRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BIoRecord::getPatientIdent, patientIdent)
                .eq(BIoRecord::getHospitalNumber, hospitalNumber)
                .eq(BIoRecord::getRealTime, new Date(time)).eq(BIoRecord::getModelCode, "crl-in")
                .eq(BIoRecord::getCreatedBy, operator)
                .and(wqpper -> wqpper.eq(BIoRecord::getSource, "hand").or().eq(BIoRecord::getSource, "care"));
        delete(queryWrapper);
    }

    default void deleteOutOld(Date ftime, String operator, String account, String patientIdent, String hospitalNumber) {
        LambdaQueryWrapper<BIoRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BIoRecord::getPatientIdent, patientIdent)
                .eq(BIoRecord::getHospitalNumber, hospitalNumber)
                .eq(BIoRecord::getTime, ftime).eq(BIoRecord::getModelCode, "crl-out")
                .eq(BIoRecord::getCreatedBy, operator);
        delete(queryWrapper);
    }

    List<IoCodeDetailVO> queryIoStatisticsListAll(@Param("modelCode") String modelCode, @Param("hospitalNumbers") Collection<String> hospitalNumbers, @Param("startTime") Date startTime, @Param("endTime") Date endTime);


    List<IoCodeDetailVO> queryIoStatisticsSumAll(@Param("modelCode") String modelCode, @Param("hospitalNumbers") Collection<String> hospitalNumbers, @Param("startTime") Date startTime, @Param("endTime") Date endTime);


    List<IoCodeDetailVO> queryIoStatisticsList(String modelCode, String hospitalNumber, Date startTime, Date endTime);


    List<IoCodeDetailVO> queryIoStatisticsSum(String modelCode, String hospitalNumber, Date startTime, Date endTime);

}


